package com.wwwarehouse.taskcenter.fragment.invite_business_information;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.ClearEditText;
import com.wwwarehouse.common.custom_widget.CustomViewPagerInternal;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.SlideBarView;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.LogUtils;
import com.wwwarehouse.common.tools.PopUpUtils;
import com.wwwarehouse.common.tripartite_widget.viewindicator.CirclePageIndicator;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.bean.InviteRankFilterBean;
import com.wwwarehouse.taskcenter.bean.InviteRankOrderBean;
import com.wwwarehouse.taskcenter.bean.InviterCountBean;
import com.wwwarehouse.taskcenter.bean.InviterRankBean;
import com.wwwarehouse.taskcenter.constant.TaskCenterConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @创建者 chenchao.
 * @创建时间 2017/10/9 18:49
 * @描述 ${TODO}
 */
@Route(path = TaskCenterConstant.SelectInviterFragment)
public class SelectInviterFragment extends BaseFragment {

    private View                    mView;
    private StateLayout             mStateLayout;
    private ElasticScrollView       mElasticScrollView;
    private CustomViewPagerInternal mVpiContain;
    private CirclePageIndicator     mPageIndicator;
    private SlideBarView            mSlideBarView;
    private ImageView               mSortBt;
    private Map                        mSelectInviterMap;
    private InviterCountBean           mSelectInviterBean;
    private List<Fragment>             mFragmentList;
    private Bundle                     mSelectInviterToChildBundle;
    private SelectInviterFragmentChild mSelectInviterFragmentChild;
    private View                       mSearchImgV;
    private ClearEditText              mSearchEdt;
    private Button                     mSearchCancelbt;
    private List<InviteRankFilterBean> mInviteRankFilterList;
    private Map                        mInviteRankingMap;
    private List<InviteRankOrderBean>  mOrderList;
    private InviteRankOrderBean        mInviteRankOrderBean;
    private List<String>               mSelectsList;
    private Bundle                     mSelectInviteBundle;
    private InviteRankFilterBean       mMInviteRankFilterBean1;
    private InviteRankFilterBean       mMInviteRankFilterBean2;
    private InviteRankFilterBean       mMInviteRankFilterBean3;
    private InviteRankFilterBean    mMInviteRankFilterBean4;
    private InviteRankFilterBean    mMInviteRankFilterBean5;
    private InviteRankFilterBean    mMInviteRankFilterBean6;
    private InviteRankFilterBean    mInviteRankFilterBean7;
    private boolean                 isDay;
    private boolean                 isWeek;
    private boolean                 isMonth;
    private boolean                 isYear;
    private String                  mStartTime;
    private String                  mEndTime;
    private LinearLayout            mEmptyLayout;
    private ImageView               mEmptyImg;
    private TextView                mEmptyTxt;
    private RelativeLayout mRlSelf;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_select_inviter, container, false);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
    }

    private void initView() {
        mStateLayout = findView(mView, R.id.sl_layout);
        mVpiContain = findView(mView, R.id.vpi_invite);
        mPageIndicator = findView(mView, R.id.cpi_indicator);
        mSlideBarView = findView(mView, R.id.sbv_slide);
        mElasticScrollView = findView(mView, R.id.esv_elastic);

        mRlSelf = findView(mView, R.id.rl_self);
        mEmptyLayout = findView(mView, R.id.ll_empty);
        mEmptyImg = findView(mView, R.id.iv_empty);
        mEmptyTxt = findView(mView, R.id.tv_empty);

    }

    private void initData() {
        mInviteRankFilterList = new ArrayList<>();//筛选条件的集合
        mInviteRankingMap = new HashMap();//请求数据的map
        getInviteRankOrderBean("asc");//升降序
        getSelectsList();//最后一个集合
        mFragmentList = new ArrayList<>();
        mElasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {
                ((BaseCardDeskActivity) mActivity).downPull_4();
                ((BaseCardDeskActivity) mActivity).hideFilterBt();
                ((BaseCardDeskActivity) mActivity).showSortBt();
                ((BaseCardDeskActivity) mActivity).showSearchImgV();

                //排序按钮
//                mSortBt = ((BaseCardDeskActivity) mActivity).getSortBt();
//                if (mSortBt.getVisibility() == View.INVISIBLE) {
//                    mSortBt.setVisibility(View.VISIBLE);
//                }
//                mSortBt.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        sortListener();
//                    }
//                });

                //不可以输入的搜索
//                mSearchImgV = ((BaseCardDeskActivity) mActivity).getSearchImgV();
//                if (mSearchImgV.getVisibility() == View.INVISIBLE) {
//                    mSearchImgV.setVisibility(View.VISIBLE);
//                }
//                mSearchImgV.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        ((BaseCardDeskActivity) mActivity).hideSearchTitle();
//                        ((BaseCardDeskActivity) mActivity).showSearchInput();
//
//                        mSearchEdt.requestFocus();
//                        showSoftKeyBoard(mSearchEdt);
//                    }
//                });


                //可以输入的搜索
//                mSearchEdt = ((BaseCardDeskActivity) mActivity).getSearchClearEdit();
//                mSearchEdt.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
                //搜索取消
//                mSearchEdt.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        ((BaseCardDeskActivity) mActivity).showSearchTitle();
//                        ((BaseCardDeskActivity) mActivity).hideSearchInput();
//
//                        hideSoftKeyBoard(mSearchEdt);
//                    }
//                });
//                mSearchEdt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
//                    @Override
//                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//                        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
//                            String searchText = mSearchEdt.getText().toString();
//
//                            if (!TextUtils.isEmpty(searchText)) {
//                                mInviteRankFilterBean7 = new InviteRankFilterBean();
//                                mInviteRankFilterBean7.setColumn("inviter_name");
//                                mInviteRankFilterBean7.setType("in");
//                                List<String> nameValueList = new ArrayList<String>();
//                                nameValueList.clear();
//                                nameValueList.add(searchText);
//                                mInviteRankFilterBean7.setValues(nameValueList);
//                                if (isDay) {
//                                    mInviteRankFilterList.clear();
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean1);
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean2);
//                                    mInviteRankFilterList.add(mInviteRankFilterBean7);
//                                    mInviteRankingMap.put("dataSet", "inviter_day");
//                                } else if (isWeek) {
//                                    mInviteRankFilterList.clear();
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean1);//暂时不传 石生未写好
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean3);
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean4);
//                                    mInviteRankFilterList.add(mInviteRankFilterBean7);
//                                    mInviteRankingMap.put("dataSet", "inviter_week");
//                                } else if (isMonth) {
//                                    mInviteRankFilterList.clear();
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean1);
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean5);
//                                    mInviteRankFilterList.add(mInviteRankFilterBean7);
//                                    mInviteRankingMap.put("dataSet", "inviter_month");
//                                } else if (isYear) {
//                                    mInviteRankFilterList.clear();
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean1);
//                                    mInviteRankFilterList.add(mMInviteRankFilterBean6);
//                                    mInviteRankFilterList.add(mInviteRankFilterBean7);
//                                    mInviteRankingMap.put("dataSet", "inviter_year");
//                                }
//                                getSelectInviter();
//                            }
//
//                            hideSoftKeyBoard(mSearchEdt);
//
//                            return true;
//                        }
//
//                        return false;
//                    }
//                });

                //取消
//                mSearchCancelbt = ((BaseCardDeskActivity) mActivity).getSearchCancelbt();
//                mSearchCancelbt.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        ((BaseCardDeskActivity) mActivity).showSearchTitle();
//                        ((BaseCardDeskActivity) mActivity).hideSearchInput();
//                        hideSoftKeyBoard(mSearchEdt);
//                        mSearchEdt.setText("");
//                        if (mInviteRankFilterBean7 != null) {
//                            mInviteRankFilterBean7 = null;
//                        }
//                        if (isDay) {
//                            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
//                            mMInviteRankFilterBean2 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean2");
//
//                            mInviteRankFilterList.clear();
//                            mInviteRankFilterList.add(mMInviteRankFilterBean1);
//                            mInviteRankFilterList.add(mMInviteRankFilterBean2);
//                            mInviteRankingMap.put("dataSet", "inviter_day");
//                        } else if (isWeek) {
//                            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
//                            mMInviteRankFilterBean3 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean3");
//                            mMInviteRankFilterBean4 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean4");
//                            //清一遍再添加 以保证每次请求都可以用这个集合
//                            mInviteRankFilterList.clear();
//                            mInviteRankFilterList.add(mMInviteRankFilterBean1);//暂时不传 石生未写好
//                            mInviteRankFilterList.add(mMInviteRankFilterBean3);
//                            mInviteRankFilterList.add(mMInviteRankFilterBean4);
//
//                            mInviteRankingMap.put("dataSet", "inviter_week");
//                        } else if (isMonth) {
//                            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
//                            mMInviteRankFilterBean5 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean5");
//                            mInviteRankFilterList.clear();
//                            mInviteRankFilterList.add(mMInviteRankFilterBean1);
//                            mInviteRankFilterList.add(mMInviteRankFilterBean5);
//                            mInviteRankingMap.put("dataSet", "inviter_month");
//                        } else if (isYear) {
//                            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
//                            mMInviteRankFilterBean6 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean6");
//                            mInviteRankFilterList.clear();
//                            mInviteRankFilterList.add(mMInviteRankFilterBean1);
//                            mInviteRankFilterList.add(mMInviteRankFilterBean6);
//                            mInviteRankingMap.put("dataSet", "inviter_year");
//                        }
//                        getSelectInviter();
//                    }
//                });
            }

            @Override
            public void onUpPull() {

            }
        });


    }

    //排序
    @Override
    public void sortClick(View anchor) {
//        super.sortClick(anchor);
        if (peekFragment() instanceof SelectInviterFragment) {
            sortListener(anchor);
        }

    }

    private String searchText;
    @Override
    public void searchNoRealTimeClick(String text) {
//        super.searchNoRealTimeClick(text);
        if (peekFragment() instanceof SelectInviterFragment) {
            if (!TextUtils.isEmpty(text)) {
                searchText = text;
                mInviteRankFilterBean7 = new InviteRankFilterBean();
                mInviteRankFilterBean7.setColumn("inviter_name");
                mInviteRankFilterBean7.setType("in");
                List<String> nameValueList = new ArrayList<String>();
                nameValueList.clear();
                nameValueList.add(text);
                mInviteRankFilterBean7.setValues(nameValueList);
                if (isDay) {
                    mInviteRankFilterList.clear();
                    mInviteRankFilterList.add(mMInviteRankFilterBean1);
                    mInviteRankFilterList.add(mMInviteRankFilterBean2);
                    mInviteRankFilterList.add(mInviteRankFilterBean7);
                    mInviteRankingMap.put("dataSet", "inviter_day");
                } else if (isWeek) {
                    mInviteRankFilterList.clear();
                    mInviteRankFilterList.add(mMInviteRankFilterBean1);//暂时不传 石生未写好
                    mInviteRankFilterList.add(mMInviteRankFilterBean3);
                    mInviteRankFilterList.add(mMInviteRankFilterBean4);
                    mInviteRankFilterList.add(mInviteRankFilterBean7);
                    mInviteRankingMap.put("dataSet", "inviter_week");
                } else if (isMonth) {
                    mInviteRankFilterList.clear();
                    mInviteRankFilterList.add(mMInviteRankFilterBean1);
                    mInviteRankFilterList.add(mMInviteRankFilterBean5);
                    mInviteRankFilterList.add(mInviteRankFilterBean7);
                    mInviteRankingMap.put("dataSet", "inviter_month");
                } else if (isYear) {
                    mInviteRankFilterList.clear();
                    mInviteRankFilterList.add(mMInviteRankFilterBean1);
                    mInviteRankFilterList.add(mMInviteRankFilterBean6);
                    mInviteRankFilterList.add(mInviteRankFilterBean7);
                    mInviteRankingMap.put("dataSet", "inviter_year");
                }
                getSelectInviter();
            }
        }

    }

    @Override
    public void cancelClick() {
//        super.cancelClick();
        if (peekFragment() instanceof SelectInviterFragment) {
            if (!TextUtils.isEmpty(searchText)) {
                searchText = "";
            }
            if (mInviteRankFilterBean7 != null) {
                mInviteRankFilterBean7 = null;
            }
            if (isDay) {
                mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
                mMInviteRankFilterBean2 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean2");

                mInviteRankFilterList.clear();
                mInviteRankFilterList.add(mMInviteRankFilterBean1);
                mInviteRankFilterList.add(mMInviteRankFilterBean2);
                mInviteRankingMap.put("dataSet", "inviter_day");
            } else if (isWeek) {
                mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
                mMInviteRankFilterBean3 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean3");
                mMInviteRankFilterBean4 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean4");
                //清一遍再添加 以保证每次请求都可以用这个集合
                mInviteRankFilterList.clear();
                mInviteRankFilterList.add(mMInviteRankFilterBean1);//暂时不传 石生未写好
                mInviteRankFilterList.add(mMInviteRankFilterBean3);
                mInviteRankFilterList.add(mMInviteRankFilterBean4);

                mInviteRankingMap.put("dataSet", "inviter_week");
            } else if (isMonth) {
                mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
                mMInviteRankFilterBean5 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean5");
                mInviteRankFilterList.clear();
                mInviteRankFilterList.add(mMInviteRankFilterBean1);
                mInviteRankFilterList.add(mMInviteRankFilterBean5);
                mInviteRankingMap.put("dataSet", "inviter_month");
            } else if (isYear) {
                mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
                mMInviteRankFilterBean6 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean6");
                mInviteRankFilterList.clear();
                mInviteRankFilterList.add(mMInviteRankFilterBean1);
                mInviteRankFilterList.add(mMInviteRankFilterBean6);
                mInviteRankingMap.put("dataSet", "inviter_year");
            }
            getSelectInviter();
        }

    }

    protected int mSelectedBubblePosition = 2;
    protected String mSort;

    private void sortListener(View anchor) {
        PopUpUtils.showBubbleInviteSort(mActivity, anchor, mSelectedBubblePosition, new PopUpUtils.OnChoiceListener() {
            @Override
            public void onChoice(int position) {
                mSelectedBubblePosition = position;
                switch (position) {
                    case 2:
                        mSort = "asc";     //正序
                        break;
                    case 3:
                        mSort = "desc ";  //倒序
                        break;
                    default:
                        break;
                }
                getInviteRankOrderBean(mSort);
                //                mInviteRankingMap.put("orders", mOrderList);
                getSelectInviter();
            }
        }, "", mActivity.getResources().getString(R.string.front_to_back), mActivity.getResources().getString(R.string.back_to_front));
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof SelectInviterFragment) {
            mActivity.setTitle(R.string.select_inviter);
        }
    }

    @Override
    public void requestDatas() {
        mSelectInviteBundle = getArguments();
        if (mSelectInviteBundle != null && mSelectInviteBundle.getString("startTime") != null && mSelectInviteBundle.getString("endTime") != null) {
            mStartTime = mSelectInviteBundle.getString("startTime");
            mEndTime = mSelectInviteBundle.getString("endTime");
        }
        //day
        if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean2") != null) {
            isDay = true;
            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
            mMInviteRankFilterBean2 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean2");

            mInviteRankFilterList.clear();
            mInviteRankFilterList.add(mMInviteRankFilterBean1);
            mInviteRankFilterList.add(mMInviteRankFilterBean2);
            mInviteRankingMap.put("dataSet", "inviter_day");

            //week
        } else if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean3") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean4") != null) {
            isWeek = true;
            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
            mMInviteRankFilterBean3 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean3");
            mMInviteRankFilterBean4 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean4");
            //清一遍再添加 以保证每次请求都可以用这个集合
            mInviteRankFilterList.clear();
            mInviteRankFilterList.add(mMInviteRankFilterBean1);//暂时不传 石生未写好
            mInviteRankFilterList.add(mMInviteRankFilterBean3);
            mInviteRankFilterList.add(mMInviteRankFilterBean4);

            mInviteRankingMap.put("dataSet", "inviter_week");
            //month
        } else if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean5") != null) {
            isMonth = true;
            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
            mMInviteRankFilterBean5 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean5");
            mInviteRankFilterList.clear();
            mInviteRankFilterList.add(mMInviteRankFilterBean1);
            mInviteRankFilterList.add(mMInviteRankFilterBean5);
            mInviteRankingMap.put("dataSet", "inviter_month");
            //year
        } else if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean6") != null) {
            isYear = true;
            mMInviteRankFilterBean1 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean1");
            mMInviteRankFilterBean6 = (InviteRankFilterBean) mSelectInviteBundle.getSerializable("mInviteRankFilterBean6");
            mInviteRankFilterList.clear();
            mInviteRankFilterList.add(mMInviteRankFilterBean1);
            mInviteRankFilterList.add(mMInviteRankFilterBean6);
            mInviteRankingMap.put("dataSet", "inviter_year");
        }
        getSelectInviter();

    }

    private void getInviteRankOrderBean(String s) {
        mOrderList = new ArrayList<>();
        mInviteRankOrderBean = new InviteRankOrderBean();
        mInviteRankOrderBean.setColumn("invite_ranking");
        mInviteRankOrderBean.setType(s);//升序
        mOrderList.add(mInviteRankOrderBean);
    }

    private void getSelectsList() {
        mSelectsList = new ArrayList<>();
        mSelectsList.add("inviter_id");
        mSelectsList.add("inviter_name");
        mSelectsList.add("register_qty");
        mSelectsList.add("inviter_url");
        mSelectsList.add("invite_ranking");
    }

    private void getSelectInviter() {
        mInviteRankingMap.put("filters", mInviteRankFilterList);
        mInviteRankingMap.put("ifCount", "true");
        mInviteRankingMap.put("ifDistinct", "true");
        mInviteRankingMap.put("page", 1);
        mInviteRankingMap.put("size", 9);
        mInviteRankingMap.put("orders", mOrderList);
        mInviteRankingMap.put("selects", mSelectsList);
        mStateLayout.showProgressView(false);
        NoHttpUtils.httpPost(TaskCenterConstant.BI_GETDATA, mInviteRankingMap, mOnResponseListener, 0);
    }

    private NoHttpUtils.OnResponseListener mOnResponseListener = new NoHttpUtils.OnResponseListener() {
        @Override
        public void onSucceed(CommonClass commonClass, int i) {
            try {
                switch (i) {
                    case 0:
                        if ("0".equals(commonClass.getCode())) {
                            InviterRankBean inviterRankBean = JSON.parseObject(commonClass.getData().toString(), InviterRankBean.class);
                            //总共多少页
                            int total = inviterRankBean.getTotal();
                            if (total == 0) {
                                if (!TextUtils.isEmpty(searchText)) {
                                    mRlSelf.setVisibility(View.GONE);
                                    mEmptyLayout.setVisibility(View.VISIBLE);

                                    mEmptyImg.setImageResource(R.drawable.search_empty);
                                    mEmptyTxt.setText(R.string.invite_search_no_result);
                                } else {
                                    mRlSelf.setVisibility(View.VISIBLE);
                                    mEmptyLayout.setVisibility(View.GONE);


                                    mStateLayout.showEmptyView(false);
                                    mStateLayout.setEmptyListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            getSelectInviter();
                                        }
                                    });
                                }

                            } else {
                                mRlSelf.setVisibility(View.VISIBLE);
                                mEmptyLayout.setVisibility(View.GONE);
                                final int page = (total % 9 == 0) ? total / 9 : total / 9 + 1;
                                mFragmentList.clear();
                                for (int j = 0; j < page; j++) {
                                    mSelectInviterToChildBundle = new Bundle();
                                    newFragment(j);
                                    mSelectInviterFragmentChild.setArguments(mSelectInviterToChildBundle);
                                    mFragmentList.add(mSelectInviterFragmentChild);
                                }
                                mVpiContain.setAdapter(new ContractFragmentPagerAdapter(getChildFragmentManager(), mFragmentList));
                                if (page <= 6) {
                                    mPageIndicator.setVisibility(View.VISIBLE);
                                    mSlideBarView.setVisibility(View.GONE);
                                    mPageIndicator.setViewPager(mVpiContain, 0);
                                } else {
                                    mPageIndicator.setVisibility(View.GONE);
                                    mSlideBarView.setVisibility(View.VISIBLE);
                                    mSlideBarView.setTotalPage(page);
                                    mSlideBarView.setOnSlideChange(new SlideBarView.OnSlideChange() {
                                        @Override
                                        public void onSlideChange(int i) {
                                            mVpiContain.setCurrentItem(page, false);
                                        }
                                    });
                                    mSlideBarView.setViewPagerInternal(mVpiContain);
                                }
                            }
                        } else {
                            mStateLayout.showSystemView(commonClass.getMsg(), false);
                            mStateLayout.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    getSelectInviter();
                                }
                            });
                        }

                        break;
                    default:
                        break;
                }
            } catch (Exception e) {
                LogUtils.showLog(e.toString());
            }

        }

        @Override
        public void onFailed(String s, int i) {
            mStateLayout.showNetworkView(false);//网络问题
            mStateLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getSelectInviter();
                }
            });
        }

        @Override
        public void onFinish(int i) {
            mStateLayout.showContentView();
        }
    };


    private void newFragment(int j) {
        mSelectInviterFragmentChild = new SelectInviterFragmentChild();
        mSelectInviterToChildBundle.putInt("page", j + 1);
        mSelectInviterToChildBundle.putString("startTime", mStartTime);
        mSelectInviterToChildBundle.putString("endTime", mEndTime);
        //day
        if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean2") != null) {
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean1", mMInviteRankFilterBean1);
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean2", mMInviteRankFilterBean2);
            if (mInviteRankFilterBean7 != null) {
                mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean7", mInviteRankFilterBean7);
            }
            mSelectInviterToChildBundle.putSerializable("mInviteRankOrderBean", mInviteRankOrderBean);
            //week
        } else if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean3") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean4") != null) {
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean1", mMInviteRankFilterBean1);
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean3", mMInviteRankFilterBean3);
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean4", mMInviteRankFilterBean4);
            if (mInviteRankFilterBean7 != null) {
                mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean7", mInviteRankFilterBean7);
            }
            mSelectInviterToChildBundle.putSerializable("mInviteRankOrderBean", mInviteRankOrderBean);
            //month
        } else if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean5") != null) {
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean1", mMInviteRankFilterBean1);
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean5", mMInviteRankFilterBean5);
            if (mInviteRankFilterBean7 != null) {
                mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean7", mInviteRankFilterBean7);
            }
            mSelectInviterToChildBundle.putSerializable("mInviteRankOrderBean", mInviteRankOrderBean);
            //year
        } else if (mSelectInviteBundle != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean1") != null && mSelectInviteBundle.getSerializable("mInviteRankFilterBean6") != null) {
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean1", mMInviteRankFilterBean1);
            mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean6", mMInviteRankFilterBean6);
            if (mInviteRankFilterBean7 != null) {
                mSelectInviterToChildBundle.putSerializable("mInviteRankFilterBean7", mInviteRankFilterBean7);
            }
            mSelectInviterToChildBundle.putSerializable("mInviteRankOrderBean", mInviteRankOrderBean);
        }


    }
}
